package assets_withdraw

import (
	"context"

	"github.com/jinzhu/copier"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type WithdrawChannelListPageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// b端渠道管理--代付通道--查询
func NewWithdrawChannelListPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawChannelListPageLogic {
	return &WithdrawChannelListPageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WithdrawChannelListPageLogic) WithdrawChannelListPage(req *types.WithdrawChannelListPageReq) (resp *types.WithdrawChannelListPageRes, err error) {
	// todo: add your logic here and delete this line
	rpc_req := &rpc.WithdrawChannelListPageReq{
		Data: &rpc.WithdrawChannel{},
		Page: &rpc.Page{},
	}
	copier.Copy(rpc_req.Data, req)
	copier.Copy(rpc_req.Page, req.Page)
	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.PayWithdraw.WithdrawChannelListPage(l.ctx, rpc_req)
	if err != nil {
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.WithdrawChannelListPageRes{}
	if rpc_resp.Data != nil {
		for i, _ := range rpc_resp.Data {
			channeldata := &types.WithDrawChannel{}
			copier.Copy(channeldata, rpc_resp.Data[i])
			resp.Data = append(resp.Data, *channeldata)
			resp.Count = rpc_resp.ResHead.Count
		}

	}
	return
}
